package com.hsylient.rabbitmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MessageConsumer {


    @RabbitListener(queues = "a_dead_letter_queue")
    public void consumerMessage(String message) {
        log.info("[死信队列-实现延时消息] 死信队列接收延时消息 {}", message);
    }


    @RabbitListener(queues = "a_business_queue")
    public void consumerMessageBefore(String message) {
        log.info("[死信队列-实现延时消息] 正常接受业务消息的队列 {}", message);
    }


    //---------------死信队列实现消息延迟注解版-------------------------------------------

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "a_business_queue2", durable = "false", autoDelete = "true",
                    arguments = {
                            @Argument(name = "x-dead-letter-exchange", value = "a_dead_letter_exchange"),
                            @Argument(name = "x-dead-letter-routing-key", value = "a_dead_letter_routing_key")
                    }),
            exchange = @Exchange(value = "a_business_exchange2", type = "direct", durable = "false", autoDelete = "true"),
            key = "a_routing_key"
    ))
    public void handleBusinessMessage(String message) {
        log.info("[死信队列(注解版)-实现延时消息] 正常接受业务消息的队列 {}", message);
        // 处理业务逻辑
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "a_dead_letter_queue2", durable = "true", autoDelete = "true"),
            exchange = @Exchange(value = "a_dead_letter_exchange2", type = "direct", durable = "false", autoDelete = "true"),
            key = "a_dead_letter_routing_key"
    ))
    public void handleDeadLetterMessage(String message) {
        log.info("[死信队列(注解版)-实现延时消息] 死信队列接收延时消息 {}", message);
    }

}
